<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <!--&lt;!&ndash; Bootstrap &ndash;&gt;-->
    <!--<link href="../css/bootstrap.min.css" rel="stylesheet">-->
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <!--<script src="../js/bootstrap.min.js"></script>-->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置
            <small>权限管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item><a href="main.html">首页</a></el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="filter-container">
            <el-button type="primary" class="butT" @click="addUser()">新建权限</el-button>
            <el-button type="primary" class="butT" @click="flashUser()">刷新</el-button>
        </div>
        <div class="box">
            <div class="filter-container">
                <el-table
                        :data="tableData"
                        style="width: 100%"
                        max-height="700">
                    <el-table-column
                            fixed
                            prop="id"
                            label="编号"
                            width="150">
                    </el-table-column>
                    <el-table-column
                            prop="name"
                            label="权限名"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="keyword"
                            label="关键词"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="description"
                            label="描述"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            fixed="right"
                            label="操作"
                            width="120">
                        <template slot-scope="scope">
                            <el-button type="primary"
                                    @click.native.prevent="deleteRow(scope.row)"
                                    type="text"
                                    size="small">
                                删除
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>

            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增用户" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="150px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="权限名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="关键词">
                                                <el-input v-model="formData.keyword"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="权限描述">
                                                <el-input v-model="formData.description"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            tableData: [{}],
            formData: {},//表单数据
            activeName:"first",
            dialogFormVisible: false,//控制添加窗口显示/隐藏
        },
        created() {
            this.findAllUser();
        },
        methods: {
            findAllUser() {
                axios.get("/user/findAllPermission.do").then(res => {
                    if (res.data.flag) {
                        this.tableData = res.data.data;
                    }
                })
            },
            deleteRow(row) {
                this.$confirm('此操作将永久删除该权限信息, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/user/delPermissionById.do?id=" + row.id).then(res => {
                        if (res.data.flag) {
                            this.tableData = res.data.data;
                        } else {
                            this.$message.error(res.data.message);
                        }

                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            addUser() {
                this.dialogFormVisible = true;
                this.formData = {};
            },
            handleAdd() {
                axios.post("/user/addPermission.do", this.formData).then(res => {
                    if (res.data.flag) {
                        this.dialogFormVisible = false;
                        this.findAllUser();
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
            },
            flashUser() {
                this.findAllUser();
            }
        }
    })
</script>
</html>
